package com.jdk.study.d2jvm.chapter05;

/**
 * @description: i++ 和 ++i 的问题
 * @author: JackLi
 * @date: 2020/4/12 20:25
 */
public class Stack08_InterviewTest {

    public static void main(String[] args) {
        Stack08_InterviewTest test = new Stack08_InterviewTest();
        test.add2();
    }

    /*
        面试题：常见的 i++ 和 ++i 的区别
     */
    public void add1() {
        /*  第1类问题    */
        //        System.out.println(this);   // com.jdk.study.d2jvm.chapter05.Stacl08_InterviewTest@2f2c9b19
        int i1 = 10;
        i1++;   // i1 = 11

        int i2 = 10;
        ++i2;   // i2 = 11

        /*
             0 bipush 10
             2 istore_1
             3 iinc 1 by 1
             6 bipush 10
             8 istore_2
             9 iinc 2 by 1
            12 return
         */
    }

    public void add2() {
        /*  第2类问题    */
        int i3 = 10;
        int i4 = i3++;  // i4 = 10

        int i5 = 10;
        int i6 = ++i5;  // i6 = 11

        /*

             0 bipush 10
             2 istore_1
             3 iload_1
             4 iinc 1 by 1
             7 istore_2
             8 bipush 10
            10 istore_3
            11 iinc 3 by 1
            14 iload_3
            15 istore 4
            17 return

         */
    }

    public void add3() {
        /*  第3类问题    */
        int i7 = 10;
        i7 = i7++;

        int i8 = 10;
        i8 = ++i8;
    }

    public void add4() {
        /*  第4类问题    */
        int i9 = 10;
        int i10 = i9++ + ++i9;
    }

}
